<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <ui:composition template="/modelo/padrao.xhtml">
        <ui:define name="conteudo">

            <p:growl id="mensagem" showDetail="true"/>

            <p:panel id="panel" header="Listagem de Análises">

                <p>
                    <p:button id="bt_inserir" value="Inserir" outcome="form_analise" icon="ui-icon-plus"/>
                </p>

                <h:form id="form_analise">
                    <p>
                        <p:panel header="Exportar para PDF ou Excel">
                            <h:commandLink>
                                <p:graphicImage library="imagem" name="pdf.png"/>
                                <pe:exporter type="pdf" 
                                             encoding="iso-8859-1"
                                             target="dt_analise"
                                             fileName="analises"
                                             subTable="true" />
                            </h:commandLink>

                            <h:commandLink>
                                <p:graphicImage library="imagem" name="excel.png" width="48" height="48"/>
                                <pe:exporter type="xlsx" 
                                             encoding="iso-8859-1"
                                             target="dt_analise" 
                                             fileName="analises"
                                             subTable="true"/>
                            </h:commandLink>
                        </p:panel>
                    </p>

                    <p:dataTable id="dt_analise"
                                 value="#{analiseBean.tipos}"
                                 var="tipo"
                                 emptyMessage="sem registros">

                        <f:facet name="header">
                            Lista de Análises
                        </f:facet>

                        <p:columnGroup type="header">
                            <p:row>
                                <p:column headerText="Análise"/>
                                <p:column headerText="Preço"/>
                                <p:column headerText="" width="55"/>
                                <p:column headerText="" width="55"/>
                            </p:row>
                        </p:columnGroup>

                        <p:subTable id="sub_dt_analise"
                                    value="#{analiseBean.obterPorTipo(tipo)}"
                                    var="analise">
                            <f:facet name="header">
                                <h:outputText value="#{tipo}" style="font-size: 1.3em"/>
                            </f:facet>

                            <p:column>
                                <h:outputText value="#{analise.nome}"/>
                            </p:column>

                            <p:column>
                                <h:outputText value="#{analise.preco}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column>

                            <p:column style="text-align: center">
                                <p:commandButton id="cb_editar"
                                                 ajax="false"
                                                 icon="ui-icon-pencil"
                                                 action="form_analise">
                                    <f:setPropertyActionListener
                                        value="#{analise}"
                                        target="#{analiseBean.analise}"/>
                                </p:commandButton>
                            </p:column>

                            <p:column style="text-align: center">
                                <p:commandButton id="cb_excluir"
                                                 icon="ui-icon-trash"
                                                 action="#{analiseBean.remover()}"
                                                 update=":form_analise:dt_analise, :mensagem">
                                    <p:confirm header="Confirmação" 
                                               message="Você tem certeza que deseja excluir esta análise?" 
                                               icon="ui-icon-alert"/>
                                    <f:setPropertyActionListener
                                        value="#{analise}"
                                        target="#{analiseBean.analise}"/>
                                </p:commandButton>
                            </p:column>
                        </p:subTable>
                    </p:dataTable>

                    <p:confirmDialog global="true">
                        <p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes"
                                         icon="ui-icon-check"/>
                        <p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no"
                                         icon="ui-icon-close"/>
                    </p:confirmDialog>
                </h:form>
            </p:panel>
            <br/><br/>
        </ui:define>
    </ui:composition>
</html>

